const COMPLETED = 4;


Components.utils.import("resource://gsync/utils.js");
Components.utils.import("resource://gsync/gsync-api.js");

var tommysync = {

    strings: null,
    
    onMenuItemSyncNow: function(event){
    
        LOG.trace("gsync#onMenuItemSyncNow() BEGIN");
        
        document.getElementById("tommysyncStatusImage").src = "chrome://tommysync/skin/gsync_16_anim.gif";
        
        //TODO error checking       
        
        g_SyncAPI.overrideRemote();
        LOG.trace("settings END onUploadBtnClicked()");
        
        var alertService = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces['nsIAlertsService']);
        
        alertService.showAlertNotification('chrome://tommysync/skin/gsync_16.png', 'Google Bookmarksync', 'Sucessfully synchronized');
        document.getElementById("tommysyncStatusImage").src = "chrome://tommysync/skin/gsync_16.png";
        
        LOG.trace("gsync#onMenuItemSyncNow() END");
    },
    
    onLoad: function(){
    
        LOG.trace("gsync#onLoad() BEGIN");
        // TODO Implement synchronisation on startup
        // initialization code
        this.strings = document.getElementById("tommysync-strings");
        LOG.trace("gsync#onLoad() END");
    },
    
    onUnLoad: function(){
    
        LOG.trace("gsync#onUnLoad() BEGIN");
        // TODO Implement synchronisation on shutdown
        LOG.trace("gsync#onUnLoad() END");
    },
    
    onPopupShowing: function(){
    
        LOG.trace("gsync#onPopupShowing() BEGIN");
        
        //TODO, read from settings
        var showSatusIcon = true;
        
        var menuItem = document.getElementById("tommysyncMenuShowStatusIcon");
        if (showSatusIcon) {
            menuItem.setAttribute("checked", "true");
        } else {
            menuItem.removeAttribute("checked");
        }
    },
    
    onToggleStatusIcon: function(event){
    
        LOG.trace("gsync#onToggleStatusIcon() BEGIN");
        //TODO implement
    },
    
    onStatusImageClick: function(event){
    
        LOG.trace("gsync#onStatusImageClick() BEGIN");
        // TODO IS This really a right click?
        // TODO Do we rally need this?
        // Right click
        if (event.button < 2) {
            //Xmarks.OpenFoxmarksSettingsDialog(); 
            alert("Clicked");
        }
    },
    
    onMenuItemMyBookmarks: function(event){
    
        LOG.trace("gsync#onMenuItemMyBookmarks() BEGIN");
        // Use Preferences ...
        openUILinkIn('http://www.google.com/bookmarks/', 'tab');
    },
    
    onMenuItemSettings: function(event){
    
        LOG.trace("gsync#onMenuItemSettings() BEGIN");
        // TODO ensure that only one dialog instance is opened...
        window.openDialog('chrome://tommysync/content/settings.xul', '', 'chrome,titlebar,toolbar,centerscreen,resizable');
    },
    
    onMenuItemAbout: function(event){
    
        LOG.trace("gsync#onMenuItemAbout() BEGIN");
        window.openDialog('chrome://tommysync/content/about.xul', '', 'chrome,titlebar,toolbar,centerscreen,resizable');
    },
};

window.addEventListener("load", tommysync.onLoad, false);
window.addEventListener("unload", tommysync.onUnLoad, false);
